// 全屏 mixins
export default {
	data() {
		return {
			fullScreen: false,
			PageMainRef: 'body',
		};
	},
	watch: {
		fullScreen(v) {
			if (v) {
				this.$refs[this.PageMainRef] && this.$refs[this.PageMainRef].requestFullscreen();
			} else if (document.fullscreenElement) {
				try {
					document.exitFullscreen && document.exitFullscreen();
				} catch (error) {
					this.fullScreen = true;
				}
			}
		},
	},
	methods: {
		checkFull() {
			var isFull = document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement;
			if (isFull === undefined) isFull = false;
			return isFull;
		},
	},
	async mounted() {
		await this.$nextTick();
		window.addEventListener('resize', () => {
			if (!this.checkFull()) {
				// 要执行的动作
				if (this.fullScreen) {
					this.fullScreen = false;
				}
			}
		});
	},
};
